﻿@using GPS.Helpers;
@{
    Layout = null;
}
<!DOCTYPE html>
<html>
<head>
    <meta name="viewport" content="initial-scale=1.0, user-scalable=no">
    <meta charset="utf-8">
    <title>Simple Polylines</title>
    <!--Google Maps -->
  
    <script src="https://maps.googleapis.com/maps/api/js?key=AIzaSyBSEvC8_SNDWgI94WFhwDW4VZoELJjQ-yM"></script>
    <style>
        html, body {
            height: 100%;
            margin: 0;
            padding: 0;
        }

        #map-canvas, #map_canvas {
            height: 100%;
        }

        html, body {
            height: auto;
        }

        #map-canvas, #map_canvas {
            height: 650px;
        }

        #panel {
            background-color: #FFFFFF;
            border: 1px solid #999999;
            left: 50%;
            margin-left: -180px;
            padding: 5px;
            position: absolute;
            top: 5px;
            z-index: 5;
        }
    </style>
    <script>
        var googleMap, googlePolyLine, googleMarker;
        var googlePoints = new google.maps.MVCArray();
        function initialize() {
            var myLatLng = new google.maps.LatLng(0, -180);

            var mapOptions = {
                zoom: 4,
                mapTypeId: google.maps.MapTypeId.ROADMAP
            };

            googleMap = new google.maps.Map(document.getElementById('googleMap'), mapOptions);

            googleMarker = new google.maps.Marker({
                map: googleMap
            });

            googlePolyLine = new google.maps.Polyline({
                path: googlePoints,
                strokeColor: '#FF0000',
                strokeOpacity: 1.0,
                strokeWeight: 2
            });

            googlePolyLine.setMap(googleMap);
        }

        google.maps.event.addDomListener(window, 'load', initialize);

    </script>
   

</head>
<body >
  
    <div style="width:600px;margin:0 auto;text-align:center">
        <h1 style="color:gray;">GPS tracking </h1>
        <h2 style="">Real Time Maps With SignalR</h2>
        <div>
            <h2>Google Maps:</h2>
            <div id="googleMap" style="position: relative; width: 600px; height: 400px;"></div>
            
        </div>
    </div>
    @*@Scripts.Render("~/bundles/jquery")*@
    <!--Reference the SignalR library. -->
    <script src="~/Scripts/jquery.signalR-1.1.2.js"></script>
    <!--Reference the autogenerated SignalR hub script. -->
    <script src="~/signalr/hubs"></script>
    <script>
        // Reference the auto-generated proxy for the hub.
        var maps = $.connection.gPS_OnlineMaps_Hub;
        maps.client.addLocations = function (data) {
            addPoints(data);
        };

        $.connection.hub.start().done(function () {
            maps.server.getLocations().done(function (data) {
                addPoints(data);
            })
        })

        function addPoints(data) {
            if (data.length > 0) {
                addGoogleMapPoints(data);
            
                alert(data.length);
            }
        }


        //To add Google Map Points
        function addGoogleMapPoints(loc) {
            var path;
            for (i = 0; i < loc.length; i++) {
                path = googlePolyLine.getPath();
                path.push(new google.maps.LatLng(loc[i].Lat, loc[i].Lng));
            }
            var pnt = loc[loc.length - 1];
            googleMarker.setPosition(new google.maps.LatLng(pnt.Lat, pnt.Lng));
            googleMap.panTo(new google.maps.LatLng(pnt.Lat, pnt.Lng));
        }

       


    </script>
</body>
</html>
